package cn.yulezhisi.web.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yulezhisi
 **/

@Api(tags = "输入说明")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/personFile")@Controller()
public class PersonFileController{
    
    private final PersonFileService personFileService;

@ApiOperation("增加")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public ResultBean add(PersonFile personFile) {
        return new ResultBean<>(personFileService.add(personFile) != null ? "success" : "fail");
    }

 @ApiOperation("删除")
    @RequestMapping(value = "/del", method = RequestMethod.DELETE)
    @ResponseBody
    public ResultBean delete(PersonFile personFile) {
        return new ResultBean<>(personFileService.delete(personFile) != 0 ? "success" : "fail");
    }
    
    @ApiOperation("修改")
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @ResponseBody
    public ResultBean update(PersonFile personFile) {
        return new ResultBean<>(personFileService.update(personFile) != 0 ? "success" : "fail");
    }
    
    @ApiOperation("查询单个")
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    @ResponseBody
    public ResultBean<PersonFile> findOne(PersonFile personFile) {
        return new ResultBean<>(personFileService.queryOne(personFile));
    }
    
    @ApiOperation("简单条件查询分页")
    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public PageResultBean<PersonFile> findPageList(PersonFile personFile, @RequestParam int page, @RequestParam int limit) {
        PageInfo<PersonFile> pageInfo = personFileService.queryListByPage(personFile, page, limit);
        return new PageResultBean<>(pageInfo.getTotal(), pageInfo.getList());
    }


}
